/**
 * A StackPanel widget for the SensorDataViewer
 */
package org.hackystat.ui.sensordatabrowser.client;

import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.StackPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A StackPanel widget for the SensorDataViewer.
 * @author David J. Nickles
 *
 */
public class ImageConsciousStackPanel extends StackPanel {
  
  private Image dataPanelImage;
  private String open;
  private String closed;
  
  /**
   * This method sets the references to the data panel's image.
   * @param img the image in the data panel
   * @param open the url of the image for an opened state
   * @param closed the url of the image for an closed state
   */
  public void setDataPanelImage(Image img, String open, String closed) {
    this.dataPanelImage = img;
    this.open = open;
    this.closed = closed;
  }
  
  /**
   * This method is overriden to add the functionality of maintaining the data panel's icon state,
   * it passes the event back to the superclass.
   * @param event the event that was generated for this stackpanel widget.
   */
  public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);
    Widget widget = getWidget(3);
    if (widget.isVisible()) {
      this.dataPanelImage.setUrl(this.open);
    } 
    else {
      this.dataPanelImage.setUrl(this.closed);
    }
  }
}
